import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.vaadinpa.data.Coordinate;
import org.vaadinpa.data.Fleet;
import org.vaadinpa.data.Fleet.FleetOrder;
import org.vaadinpa.data.Planet;
import org.vaadinpa.data.Resource;
import org.vaadinpa.data.Universe;
import org.vaadinpa.data.ships.Hecuba;
import org.vaadinpa.data.ships.Helen;
import org.vaadinpa.data.ships.Menelaus;
import org.vaadinpa.data.ships.Priam;
import org.vaadinpa.logic.CommandHandler;
import org.vaadinpa.logic.commands.TickCommand;

public class BattleTest {

	private Planet p1;
	private Planet p2;
	private Fleet attacker;

	public void buildSimpleData() {

		p1 = new Planet(Coordinate.getRandom());
		attacker = new Fleet(p1.coords, "fuu");
		p1.fleets.add(attacker);
		attacker.addShips(new Priam(), 100);

		p2 = new Planet(Coordinate.getRandom());
		p2.homeFleet.addShips(new Priam(), 100);

		attacker.location = p2.coords;
		attacker.currentOrder = FleetOrder.ATTACK;

		Universe.instance.put(p1.coords, p1);
		Universe.instance.put(p2.coords, p2);
	}

	public void buildRoidData() {
		p2.addRoids(Resource.METAL, 100);
		attacker.addShips(new Helen(), 10);
	}

	public void buildData() {

		p1 = new Planet(Coordinate.getRandom());
		attacker = new Fleet(p1.coords, "fuu");
		p1.fleets.add(attacker);

		p2 = new Planet(Coordinate.getRandom());
		p2.homeFleet.addShips(new Menelaus(), 1);

		attacker.location = p2.coords;
		attacker.currentOrder = FleetOrder.ATTACK;

		Universe.instance.put(p1.coords, p1);
		Universe.instance.put(p2.coords, p2);

		p2.addRoids(Resource.METAL, 100);
		attacker.addShips(new Hecuba(), 50);
	}

	@Test
	public void testSimpleBattle() {

		buildSimpleData();
		CommandHandler.handle(new TickCommand());

		assertTrue(p1.homeFleet.get(new Priam()) < 100);
		assertTrue(p2.homeFleet.get(new Priam()) < 100);
	}

	@Test
	public void testRoidBattle() {

		buildSimpleData();
		buildRoidData();
		CommandHandler.handle(new TickCommand());

		System.out.println(attacker.get(new Hecuba()));
		System.out.println(p2.roids.get(Resource.METAL));
		assertTrue(p2.roids.get(Resource.METAL) < 100);
	}

	@Test
	public void testRoidBattle2() {

		buildData();
		CommandHandler.handle(new TickCommand());

		System.out.println(attacker.get(new Hecuba()));
		System.out.println(p2.roids.get(Resource.METAL));
		assertTrue(p2.roids.get(Resource.METAL) < 100);
	}
}
